#ifndef DATA_FRAME_H_
#define DATA_FRAME_H_

#include "data_holder.h"

// enum MESSAGE_ID
// {
//     ID_GET_FIRMWARE_INFO = 0,
//     ID_GET_ROBOT_INFO,
//     ID_SET_ROBOT_POSE_PARAMETER,
//     ID_GET_ROBOT_POSE_PARAMETER,
//     ID_SET_ROBOT_ALARM_PARAMETER,
//     ID_GET_ROBOT_ALARM_PARAMETER,
//     ID_SET_ROBOT_EVENT_PARAMETER,
//     ID_GET_ROBOT_EVENT_PARAMETER,
//     ID_SET_ROBOT_MOTOR_PARAMETER,
//     ID_GET_ROBOT_MOTOR_PARAMETER,
//     ID_SET_ROBOT_FUNCTION_CONFIGURATION,
//     ID_GET_ROBOT_FUNCTION_CONFIGURATION,
//     ID_SET_ROBOT_SIMULATION_PARAMETER,
//     ID_GET_ROBOT_SIMULATION_PARAMETER,
//     ID_SET_ROBOT_FLOOR_PID_PARAMETER,
//     ID_GET_ROBOT_FLOOR_PID_PARAMETER,
//     ID_SET_ROBOT_WALL_PID_PARAMETER,
//     ID_GET_ROBOT_WALL_PID_PARAMETER,
//     ID_SET_POOL_PARAMETER,
//     ID_GET_POOL_PARAMETER,
//     ID_SET_CONTROL_CMD,
//     ID_GET_CONTROL_CMD,
//     ID_SET_ACTION_GROUP,
//     ID_GET_ACTION_GROUP,
//     ID_SET_ROBOT_CALIBRATION_PARAMETER,
//     ID_GET_ROBOT_CALIBRATION_PARAMETER,
//     ID_SET_MANUAL_CONTROL,
//     ID_GET_SYSTEM_TIME,
//     ID_GET_RAW_IMU_DATA,
//     ID_GET_IMU_VARIANCE,
//     ID_GET_IMU_TEST_DATA,
//     ID_GET_QUATERNION_DATA,
//     ID_GET_POSE_DATA,
//     ID_GET_DEPTH_DATA,
//     ID_GET_WATER_TEMPERATURE_DATA,
//     ID_GET_INFRARED_DATA,
//     ID_GET_PID_DATA,
//     ID_GET_POWER_DATA,
//     ID_GET_DEBUG_STATE,
//     ID_GET_DEBUG_MODE,
//     ID_GET_ACTION_PARAMETER,
//     ID_GET_DYNAMIC_PARAMETER,
//     ID_CALIBRATE_IMU,
//     ID_CALIBRATE_GYRO,
//     ID_CALIBRATE_DEPTH,
//     ID_GET_THETA_HISTOGRAM,
//     ID_GET_FAULT_RECORDS,
//     ID_GET_CUSTOM_DEBUG_DATA,
//     ID_CHANGE_TO_IOT_DATAFRAME = 0xF1,
//     ID_MESSGAE_MAX
// };

// enum COMMUNICATION_MESSAGE_ID
// {
//     COMMUNICATION_ID_SET_ROBOT_INFO = 0x01,
//     COMMUNICATION_ID_SET_POOL_PARAMETER = 0x02,
//     // COMMUNICATION_ID_GET_ROBOT_INFO = 0x03,
//     // COMMUNICATION_ID_GET_POOL_PARAMETER = 0x04,
//     COMMUNICATION_ID_GET_RUNNING_HOURS = 0x03,
//     COMMUNICATION_ID_GET_RUNNING_MINUTES_AND_SECONDS = 0x04,
//     COMMUNICATION_ID_GET_WATER_TEMPERATURE_DATA = 0x05,
//     COMMUNICATION_ID_GET_DEPTH_DATA = 0x06,

//     COMMUNICATION_ID_CALIBRATE_DEPTH = 0x1D,
//     COMMUNICATION_ID_CALIBRATE_IMU = 0x1A,
//     COMMUNICATION_ID_CALIBRATE_WATER_TEMPERATURE = 0x1E,
//     COMMUNICATION_ID_SET_START_PUMP = 0x08,
//     COMMUNICATION_ID_SET_STOP_PUMP = 0x09,
//     COMMUNICATION_ID_SET_MANUAL_CONTROL = 0x0A,
//     COMMUNICATION_ID_SET_STOP_STANDBY = 0x0F,
//     COMMUNICATION_ID_GET_POWER_VOLTAGE = 0x20,
//     COMMUNICATION_ID_GET_PUMP_CURRENT = 0x21,
//     COMMUNICATION_ID_GET_LEFT_MOTOR_CURRENT = 0x22,
//     COMMUNICATION_ID_GET_RIGHT_MOTOR_CURRENT = 0x23,
//     COMMUNICATION_ID_GET_FAULT_CODE = 0x30,
//     COMMUNICATION_ID_GET_RAW_IMU = 0x25,
//     COMMUNICATION_ID_GET_ROBOT_POSE = 0x26,
//     COMMUNICATION_ID_SET_CLEANING_MODE_ALL = 0x03D,
//     COMMUNICATION_ID_SET_CLEANING_MODE_FLOOR = 0x3E,
//     COMMUNICATION_ID_SET_CLEANING_MODE_WALL = 0x3F,
//     COMMUNICATION_ID_SET_CLEANING_MODE_WATERLINE = 0x40,
//     COMMUNICATION_ID_RETURN_TO_WATERLINE = 0x51,
//     COMMUNICATION_ID_MESSGAE_MAX
// };

enum BLUETOOTH_MESSAGE_ID
{
    BLUETOOTH_ID_SET_PARAMETER = 0,
    BLUETOOTH_ID_GET_PARAMETER,
    BLUETOOTH_ID_RESET,
    BLUETOOTH_ID_FIRST_TIME,
    BLUETOOTH_ID_NOT_FIRST_TIME,
    BLUETOOTH_ID_OK,
    BLUETOOTH_ID_GET_ROBOT_STATIC_PARAMETER,
    BLUETOOTH_ID_GET_RAW_IMU_DATA,
    BLUETOOTH_ID_GET_POWER_DATA,
    BLUETOOTH_ID_CALIBRATE_GYRO,
    BLUETOOTH_ID_MESSGAE_MAX,
};

enum IOT_MESSAGE_ID
{
    IOT_ID_HEARTBEAT = 0,
    IOT_ID_GET_PRODUCT_INFO,
    IOT_ID_NETWORK_STATE,
    IOT_ID_RESET_WIFI,
    IOT_ID_SET_DP,
    IOT_ID_REPORT_DP,
    IOT_ID_REPORT_DP_SYN,
    IOT_ID_REPORT_DP_WITH_TIMESTAMP,
    IOT_ID_REPORT_DP_WITH_TIMESTAMP_SYN,
    IOT_ID_GET_STATE,
    IOT_ID_OTA_BEGIN,
    IOT_ID_OTA_TRANSMIT,
    IOT_ID_GET_OTA_STATE,
    IOT_ID_OTA_FINISH,
    IOT_ID_OTA_RESET,
    IOT_ID_GET_UTC_TIME = 0x1B,
    IOT_ID_GET_LOCAL_TIME = 0x1C,
    IOT_ID_SET_SERIAL_NUMBER = 0x20,
    IOT_ID_GET_SERIAL_NUMBER = 0x21,
    IOT_ID_PRODUCTION_TEST_CMD = 0x22,
    IOT_ID_GET_CALIBRATED_PARAMETER = 0x23,
    IOT_ID_GET_DEVICE_NAME = 0x24,
    IOT_ID_FORWARD_TEST = 0xF0,
    IOT_ID_CHANGE_TO_DEBUG_DATAFRAME,
    IOT_ID_MESSGAE_MAX,
};


enum DP_ID
{
    // 运行模式
    DP_ID_OPERATION_MODE = 0,
    DP_ID_CLEANING_MODE,
    // 泳池参数
    DP_ID_POOL_SHAPE,
    DP_ID_POOL_LENGTH,
    DP_ID_POOL_WIDTH,
    DP_ID_POOL_DEPTH,
    DP_ID_POOL_SURFACE_MATERIAL,
    DP_ID_POOL_FLOOR_TYPE,
    DP_ID_POOL_FLOOR_MAX_ANGLE,
    // 遥控指令
    DP_ID_MANUAL_MOVEMENT_CONTROL,
    DP_ID_MANUAL_PUMP_CONTROL,
    DP_ID_AUTO_RETURN_BACK,
    DP_ID_AREA_WASHING,
    // 错误
    DP_ID_FAULT_ALARM_NOTIFICATION,
    // 校准
    DP_ID_CALIBRATE_SENSOR,
    // 预约指令
    DP_ID_WASHING_CYCLE_TIME,
    DP_ID_DELAY_START,
    DP_ID_WEEKLY_SCHEDULE_BITMAP,
    DP_ID_WEEKLY_SCHEDULE_TIME,
    DP_ID_INTERVAL_SCHEDULE,
    // 路径模式
    DP_ID_ROUTE_MODE,
    DP_ID_FLOOR_ROUTE_MODE,
    DP_ID_WALL_ROUTE_MODE,
    // 运行时间
    DP_ID_TOTAL_RUNNING_TIME,
    DP_ID_TOTAL_WASHING_TIME,
    // 实时数据
    DP_ID_POWER_VOLTAGE_DATA,
    DP_ID_LEFT_MOTOR_CURRENT_DATA,
    DP_ID_LEFT_MOTOR_STATE,
    DP_ID_RIGHT_MOTOR_CURRENT_DATA,
    DP_ID_RIGHT_MOTOR_STATE,
    DP_ID_PUMP_MOTOR_CURRENT_DATA,
    DP_ID_PUMP_MOTOR_STATE,

    DP_ID_IMU_AX_DATA,
    DP_ID_IMU_AY_DATA,
    DP_ID_IMU_AZ_DATA,
    DP_ID_IMU_GX_DATA,
    DP_ID_IMU_GY_DATA,
    DP_ID_IMU_GZ_DATA,

    DP_ID_DEPTH_DATA,
    DP_ID_MAX_DEPTH_DATA,
    DP_ID_MIN_DEPTH_DATA,

    DP_ID_TEMPERATURE_DATA,

    DP_ID_INFRARED_DATA,
    DP_ID_INFRARED_CALIBRATION_RESULT,

    DP_ID_ANGLE_ROLL_DATA,
    DP_ID_ANGLE_PITCH_DATA,
    DP_ID_ANGLE_YAW_DATA,
    DP_ID_ANGLE_THETA_DATA,
    DP_ID_ANGLE_BETA_DATA,
    DP_ID_POSE_DATA,

    DP_ID_BATTERY_LEVEL,

    // 标定数据
    DP_ID_POWER_VOLTAGE_K,
    DP_ID_POWER_VOLTAGE_B,
    DP_ID_LEFT_MOTOR_CURRENT_K,
    DP_ID_LEFT_MOTOR_CURRENT_B,
    DP_ID_RIGHT_MOTOR_CURRENT_K,
    DP_ID_RIGHT_MOTOR_CURRENT_B,
    DP_ID_PUMP_MOTOR_CURRENT_K,
    DP_ID_PUMP_MOTOR_CURRENT_B,

    DP_ID_IMU_AX_BIAS_DATA,
    DP_ID_IMU_AY_BIAS_DATA,
    DP_ID_IMU_AZ_BIAS_DATA,
    DP_ID_IMU_GX_BIAS_DATA,
    DP_ID_IMU_GY_BIAS_DATA,
    DP_ID_IMU_GZ_BIAS_DATA,

    DP_ID_DEPTH_REFERENCE,
    DP_ID_WATERLINE_DEPTH_BASELINE,
    DP_ID_TEMPERATURE_BIAS_DATA,
    // 警告记录
    DP_ID_FAULT_ALARM_RECORDS,
    DP_ID_LED,
    DP_ID_SYSTEM_TIME,
    DP_ID_STATE_BITMAP,
    DP_ID_POOL_SHAPE_ADAPTIVE_ROUTE_MODE,
    DP_ID_FLOOR_ROUTE_MODE_CONFIGURATION,
    DP_ID_WALL_ROUTE_MODE_CONFIGURATION,
    DP_ID_COMBINATION_ROUTE_MODE_CONFIGURATION,
    DP_ID_ALL_POOL_ROUTE_MODE_CONFIGURATION,
    DP_ID_WEEKLY_SCHEDULE_GET,
    DP_ID_CUSTOM_FUNCTION,
    DP_ID_ROBOT_FUNCTION_INFO,
    DP_ID_SMART_CLEANING,
    
    DP_ID_IMU_AX_VAR,
    DP_ID_IMU_AY_VAR,
    DP_ID_IMU_AZ_VAR,
    DP_ID_IMU_GX_VAR,
    DP_ID_IMU_GY_VAR,
    DP_ID_IMU_GZ_VAR,

    DP_ID_LEFT_MOTOR_PWM,
    DP_ID_RIGHT_MOTOR_PWM,
    DP_ID_PUMP_MOTOR_PWM,

    DP_ID_POWER_BOX_TEMPERATURE = 0x60,
    DP_ID_WATER_SPEED = 0x61,

    // 分析数据
    DP_ID_POOL_LENGTH_TIME,
    DP_ID_POOL_UP_WALL_TIME,
    DP_ID_POOL_DOWN_WALL_TIME,

    DP_ID_MEASURED_POOL_LENGTH,
    DP_ID_MEASURED_POOL_WIDTH,
    DP_ID_MEASURED_POOL_DEPTH,
    DP_ID_MEASURED_POOL_FLOOR_ANGLE,

    DP_ID_TOUCH_WALL_COUNT,
    DP_ID_INFRARED_TOUCH_WALL_COUNT,
    DP_ID_POSE_TOUCH_WALL_COUNT,
    DP_ID_BUMP_TOUCH_WALL_COUNT,
    DP_ID_PWM_TOUCH_WALL_COUNT,
    DP_ID_TOUCH_WALL_TIMEOUT_COUNT,
    DP_ID_START_ON_FLOOR_COUNT,
    DP_ID_START_ON_WALL_COUNT,

    DP_ID_FLOOR_MODE_USAGE_TOTAL_TIME,
    DP_ID_WALL_MODE_USAGE_TOTAL_TIME,
    DP_ID_ALL_POLL_MODE_USAGE_TOTAL_TIME,
    DP_ID_WATERLINE_MODE_USAGE_TOTAL_TIME,
    DP_ID_COMBINATION_MODE_USAGE_TOTAL_TIME,
    DP_ID_AREA_MODE_USAGE_TOTAL_TIME,
    DP_ID_MANUAL_MODE_USAGE_TOTAL_TIME,

    DP_ID_FLOOR_MODE_USAGE_COUNT,
    DP_ID_WALL_MODE_USAGE_COUNT,
    DP_ID_ALL_POLL_MODE_USAGE_COUNT,
    DP_ID_WATERLINE_MODE_USAGE_COUNT,
    DP_ID_COMBINATION_MODE_USAGE_COUNT,
    DP_ID_AREA_MODE_USAGE_COUNT,
    DP_ID_MANUAL_MODE_USAGE_COUNT,

    DP_ID_ON_FLOOR_STUCK_COUNT,
    DP_ID_ON_FLOOR_STUCK_TYPE,
    DP_ID_ON_FLOOR_STUCK_TIME_SPENT,

    DP_ID_UP_WALL_STUCK_COUNT,
    DP_ID_DOWN_WALL_STUCK_COUNT,
    DP_ID_DOWN_WALL_STUCK_TIME_SPENT,

    DP_ID_DYNAMIC_PARAMETER,
    DP_ID_ACTION_PARAMETER,

    DP_ID_FUNCTION_CONFIGURATION,
    DP_ID_MOTOR_CONFIGURATION,
    DP_ID_EVENT_CONFIGURATION,
    DP_ID_SIMULATION_CONFIGURATION,
    DP_ID_DEBUG_DATA,
    DP_ID_MESSAGE_MAX = 0xFF,
};

class Notify
{
public:
    // virtual void update(const MESSAGE_ID id, void *data){};
    // virtual void update(const DEPTH_MESSAGE_ID id, void *data){};
    // virtual void update(const COMMUNICATION_MESSAGE_ID id, void *data){};
#if LAGACY_BLUETOOTH_ENABLE
    virtual void update(const BLUETOOTH_MESSAGE_ID id, void *data){};
#endif
    virtual void update(const IOT_MESSAGE_ID id, void *data){};
    virtual void update(const DP_ID id, void *data){};
};

class Dataframe
{
public:
    virtual bool init() = 0;
    virtual void register_notify(const unsigned int id, Notify *_nf) = 0;
    virtual bool data_recv(unsigned char c) = 0;
    virtual bool data_parse() = 0;
    virtual bool interact(const unsigned int id) = 0;
    virtual void reset_state() = 0;
};

#endif
